const path = require('path')


const PORT = process.env.PORT
const scripts = []
if( process.env.NODE_ENV == "production" ){
  scripts.push({src: 'https://hm.baidu.com/hm.js?553f794f1d2960ff84b395246f796eb0'})
}

module.exports = {
  mode: 'universal',
  server: {
    port: PORT,
    host: '0.0.0.0'
  },  
  env: {
    BASE_URL: process.env.BASE_URL,
    NODE_ENV: process.env.NODE_ENV
  },
  /*
  ** Headers of the page
  */
  head: {
    title: '图一波-图片素材库', // process.env.npm_package_name || '',
    meta: [
      {
        charset: 'utf-8'
      }, {
        name: 'viewport',
        content: 'width=device-width,height=device-height,initial-scale=1,user-scalable=no'
      }, {
        name: 'description',
        content: '图一波(tuyibo.cn) 为用户提供免费的高清无版权图片素材资源下载,持续更新图片资料,找图片素材请记住tuyibo.cn'
      }, {
        name: 'keywords',
        content: 'tuyibo.cn,tuyibo,图一波,Ui设计素材,界面设计素材,图库,图片,图片下载,网页UI素材,高清大图,高清,矢量,AI,EPS,PSD,免费素材'
      }
    ],
    link: [
      {
        rel: 'icon',
        type: 'image/x-icon',
        href: '/favicon.ico'
      }
    ],
    script: scripts
  },
  /*
  ** Customize the progress-bar color
  */
  loading: {
    color: '#fff'
  },
  /*
  ** Global CSS
  */
  css: [
    'element-ui/lib/theme-chalk/index.css', 'element-ui/lib/theme-chalk/display.css'
    //'@/components/framework/theme/element-ui/index',
  ],
  styleResources: {
    less: ['./assets/theme/colors.less']
  },
  /*
  ** Plugins to load before mounting the App
  */
  plugins: [
    { src: '@/plugins/icons', ssr: true },
    {src:'@/plugins/clipboard2',ssr:true},
    '@/plugins/element-ui',
    '@/plugins/axios', 
    {
      src: '~/plugins/vue-masonry',
      ssr: false
    },
    { src: '@/plugins/tongji.js', ssr: false }
  ],
  /*
  ** Nuxt.js dev-modules
  */
  buildModules: [// Doc: https://github.com/nuxt-community/eslint-module '@nuxtjs/eslint-module'
    ],
  /*
  ** Nuxt.js modules
  */
  modules: [
    // Doc: https://axios.nuxtjs.org/usage
    '@nuxtjs/axios',
    // '@nuxtjs/pwa',
    '@nuxtjs/proxy',
    '@nuxtjs/style-resources',
    'cookie-universal-nuxt'
  ],
  proxy: [
    // [
    //   '/api/wbms', {
    //     target: 'http://192.168.0.17:8089'
    //   }
    // ], 
    //, pathRewrite: {'^/api/dev': '/api'}
  ],
  /*
  ** Axios module configuration
  ** See https://axios.nuxtjs.org/options
  */
  axios: {
    baseURL: `http://localhost:${PORT}`,
    proxy: true
  },
  /*
  ** Build configuration
  */
  build: {
    transpile: [/^element-ui/],
    /*
    */
    extend(config, ctx) {
      config.resolve.extensions = ['.js', '.json', '.mjs', '.vue']
      config.resolve.alias = {
        '@': path.join(__dirname, './'),
        ...config.resolve.alias
      }
      
      const svgRule = config.module.rules.find(rule => rule.test.test('.svg'))
      svgRule.exclude = [path.resolve(__dirname, 'assets/icons')]
      // Includes /icons/svg for svg-sprite-loader
      config.module.rules.push({
        test: /\.svg$/,
        include: [path.resolve(__dirname, 'assets/icons')],
        loader: 'svg-sprite-loader',
        options: {
          symbolId: 'icon-[name]',
        },
      }) 
    },

    // babel: {
    //   presets: ['es2015', 'stage-0']
    // }
  },
  // serverMiddleware:['~/servers/comm/middleware.js']
}
